package com.site.model.backend.system;


import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import com.site.util.base.po.BaseApplicationInfo;


/**
 * 系统用户表实体（包含裁判）
 * @author fate 2012-4-10
 *
 */
@Entity
@Table(name="m_system_users")
public class UsersInfo extends BaseApplicationInfo{
	private static final long serialVersionUID = 1L;
	/* 
	 * 用户Id
	 */
    private Long userId;
    /*
     *用户名
     */
    private String userName;
    /* 
     * 密码(md5) 
     */
    private String passWord;
    /*
     * 邮箱
     */
    private String email;
    /*
     * 状态(Y:锁定，N：未锁定) 
     */
    private String status; 
    /*
     * 备注 
     */
    private String remark;
    /*
     * 角色
     */
    private Set<RoleInfo> roleSet = new HashSet<RoleInfo>();
    /*
     * 真实名称
     */
    private String realName;
    
	@Column(name="status")
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	@Column(name="remark")
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	@Column(name="email")
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	@Column(name="realname")
	public String getRealName() {
		return realName;
	}
	public void setRealName(String realName) {
		this.realName = realName;
	}
	@Column(name = "USER_NAME")
	public String getUserName() {
		return userName;
	}
	@Column(name="password")
	public String getPassWord() {
		return passWord;
	}
	public void setPassWord(String passWord) {
		this.passWord = passWord;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	 
	@Id
    @GeneratedValue
    @Column(name="user_id")
	public Long getUserId() {
		return userId;
	}
	public void setUserId(Long userId) {
		this.userId = userId;
	}
	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof UsersInfo)) {
			return false;
		} else if (((UsersInfo) obj).getUserId() != null && userId != null
				&& ((UsersInfo) obj).getUserId().intValue() == userId.intValue()) {
			return true;
		} else {
			return super.equals(obj);
		}
	}

	@Override
	public int hashCode() {
		return userId.hashCode();
	}
	
	@ManyToMany(fetch = FetchType.LAZY, cascade=CascadeType.REFRESH)
	@JoinTable(name="m_system_role_user", joinColumns = @JoinColumn(name="USER_ID"), inverseJoinColumns = @JoinColumn(name="ROLE_ID"))
	public Set<RoleInfo> getRoleSet() {
		return roleSet;
	}
	public void setRoleSet(Set<RoleInfo> roleSet) {
		this.roleSet = roleSet;
	}
}